import Vue from 'vue'
import App from './App'
import store from './store'
import io from "./js/weapp.socket.io.js"
import api from "./api/index.js"

import {
	openDatabase,
	isOpenDatabase,
	closeDataBase,
	transaction,
	executeSql,
	selectSql
} from "./tool/dbOp.js"
import tabbar from "@/components/tabbar"
import navbar from "@/components/navbar"
// import {targetDataBaseOpen,createTable,addData,selectSqlAll} from "./tool/opChatRecord.js"
import opChatDataBase from "./tool/opChatRecord.js"
Vue.component('tabbar', tabbar)
Vue.component('navbar', navbar)
Vue.config.productionTip = false
Vue.prototype.$initSocket = function(userId) {
	Vue.prototype.$socket = io.connect(('http://192.168.0.106:3000'))
	if (userId) {
		Vue.prototype.$socket.emit('user_connect', {
			userId
		})
		console.log('注册用户')
	}
}

Vue.prototype.$api = api
Vue.prototype.$opChatDB = opChatDataBase

Vue.prototype.$openDatabase = openDatabase
Vue.prototype.$isOpenDatabase = isOpenDatabase
Vue.prototype.$closeDataBase = closeDataBase
Vue.prototype.$transaction = transaction
Vue.prototype.$executeSql = executeSql
Vue.prototype.$selectSql = selectSql
Vue.prototype.$getUserInfo = () => {
	return api.getCurrentAccountInfo().then(res => {
		console.log('用户信息', res)
		store.commit('setUserInfo', res.data.userInfo)
		return res
	})
}
Vue.prototype.$replaceTableNameLine = function(str) {
	console.log('我执行了吗',str)
	return str.replace(/-/g, '_')
}
App.mpType = 'app'

// 引入全局uView
import uView from 'uview-ui'
Vue.use(uView);

const app = new Vue({
	...App,
	store
})
app.$mount()
